# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  nix.binaryCaches = [
    "https://mirrors.ustc.edu.cn/nix-channels/store"
    "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
  ];
  nix.gc.automatic = true;
  nix.gc.options = "--delete-older-than 8d";

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # The global useDHCP flag is deprecated, therefore explicitly set to false here.
  # Per-interface useDHCP will be mandatory in the future, so this generated config
  # replicates the default behaviour.
  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  networking = {
    hostName = "DnF-NIXOS";
    useDHCP = false;
    firewall.enable = false;
    interfaces.enp1s0.useDHCP = true;
    resolvconf.extraOptions = [
      "ndots:1"
      "rotate"
    ];
    proxy = {
      #noProxy = "127.0.0.1,localhost,thunisoft.com,172.{1..255}.{1..255}.{1..255}";
      noProxy = "127.0.0.1,localhost,thunisoft.com,*.thunisoft.com";
      #allProxy = "socks5://127.0.0.1:1080";
      httpProxy = "socks5://127.0.0.1:1080";
      httpsProxy = "socks5://127.0.0.1:1080";
    };
   };

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Select internationalisation properties.
   i18n = {
  #   consoleFont = "Lat2-Terminus16";
  #   consoleKeyMap = "us";
     supportedLocales = [ "zh_CN.UTF-8/UTF-8"];
     defaultLocale = "zh_CN.UTF-8";
     inputMethod.enabled = "fcitx";
     inputMethod.fcitx.engines = with pkgs.fcitx-engines; [ m17n ];
   };
   console = {
     keyMap = "us";
   };

   fonts = {
     enableFontDir = true;
     enableGhostscriptFonts = true;
     fontconfig = {
       enable = true;
       defaultFonts = {
         monospace = [ "Sarasa Mono SC" ];
         sansSerif = [ "Sarasa UI SC" ];
         serif = [ "Sarasa UI SC" ];
       };
     };
     fonts = with pkgs; [
       inconsolata
       jetbrains-mono
       dejavu_fonts
       dejavu_fontsEnv
       noto-fonts
       noto-fonts-cjk
       noto-fonts-emoji
       sarasa-gothic
       wqy_microhei
       wqy_zenhei
     ];
  };

  # Set your time zone.
  # time.timeZone = "Europe/Amsterdam";
  time.timeZone = "Asia/Shanghai";

  # List packages installed in system profile. To search, run:
  # $ nix search wget
   nixpkgs.config.allowUnfree = true;

   environment.variables = {
       JAVA_HOME = "${pkgs.jdk8.home}/";
   };

   environment.systemPackages = with pkgs; [

     ark
     aria2
     abiword
     appimage-run
     anydesk

     bash-completion
     #bcompare

     chromium
     curl

     dos2unix
     direnv
 
    # eclipses.eclipse-java
    # eclipses.eclipse-platform

     fcitx
     fcitx-configtool
     firefox
     fzf
     # 截图
     flameshot
     fontconfig

     gcc
     git

     htop

     iptables
     inetutils

     jq
     jetbrains.idea-ultimate

     killall
     kdeApplications.krdc

     libidn2
     latte-dock
     libreoffice-fresh

     maven

     netdata
     nix-index
     nodejs
     neofetch

     okular
     #oraclejdk8
     openjdk8

     pciutils
     python3
     python3.pkgs.pip 
     python3.pkgs.setuptools 

     refind
     #shadowsocks-libev

     tree
     transmission
     teamviewer
     #termius

     vim
     v2ray
     vscode-with-extensions

     wget 
     #wpsoffice

     xrdp
     xorg.xhost
     xclip
     #x11docker
   ];


  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  programs = {
    bash = {
      enableCompletion = true;
      promptInit = 
	''
	  if [ "$TERM" != "dumb" -o -n "$INSIDE_EMACS" ]; then
	    PROMPT_COLOR="1;31m"
	    let $UID && PROMPT_COLOR="1;32m"
	    if [ -n "$INSIDE_EMACS" -o "$TERM" == "eterm" -o "$TERM" == "eterm-color" ]; then
	      PS1="\[\033[$PROMPT_COLOR\][\u@\h:\W]\\$\[\033[0m\] "
	    else
	      PS1="\[\033[$PROMPT_COLOR\][\[\e]0;\u@\h: \W\a\]\u@\h:\W]\\$\[\033[0m\] "
	    fi
	    if test "$TERM" = "xterm"; then
	      PS1="\[\033]2;\h:\u:\w\007\]$PS1"
	    fi
	  fi
	'';
    };

    java = {
      enable = true;
      package = pkgs.openjdk8;
    };
    
    gnupg.agent =  { enable = true; };

    ssh.startAgent = true;
    vim.defaultEditor = true;
  };
  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;


  # Enable CUPS to print documents.
  # services.printing.enable = true;:

  # Enable sound.
   sound.enable = true;
   hardware = {
     bluetooth = { 
       enable = true;
       config = {
         General = {
           ControllerMode = "bredr";
         };
       };
     };

     pulseaudio = {
       enable = true;
     };
   };
  # hardware.pulseaudio.enable = true;

  # Enable the X11 windowing system.
   services.xserver.enable = true;
   services.xserver.layout = "us";
   services.xserver.xkbOptions = "eurosign:e";

  # Enable touchpad support.
  # services.xserver.libinput.enable = true;

  # Enable the KDE Desktop Environment.
   services.xserver.displayManager.sddm.enable = true;
   services.xserver.desktopManager.plasma5.enable = true;
   services = {
     netdata = {
       enable = true;
     };
     xrdp = {
       enable = true;
       defaultWindowManager = "plasma5"; 
     }; 

     openssh = {
       enable = true;
       forwardX11 = true;
       ports = [21223];
       passwordAuthentication = false;
       banner = '' 
  _       ____  ______     ___    ____  ______   __  _________
 | |     / / / / / __ \   /   |  / __ \/ ____/  /  |/  / ____/
 | | /| / / /_/ / / / /  / /| | / /_/ / __/    / /|_/ / __/   
 | |/ |/ / __  / /_/ /  / ___ |/ _, _/ /___   / /  / / /___   
 |__/|__/_/ /_/\____/  /_/  |_/_/ |_/_____/  /_/  /_/_____/   


       '';
     };

     resolved = {
       enable = false;
       fallbackDns = [
         "223.5.5.5"
         "172.25.25.25"
         "8.8.8.8"
         "2001:4860:4860::8844"
       ];
     };

     samba = {
       enable = true;
       enableNmbd = true;
       shares = {
         data = {
           path = "/data";
           browseable = "yes";
           "guest ok" = "yes";
           "read only" = false;
           comment = "dnf nixos data";
         };
       };
     };

     tomcat = {
       enable = false;
       #enable = false;
       #package = pkgs.tomcat7;
       package = pkgs.tomcat8;
       webapps = [pkgs.tomcat8.webapps];
#       jdk = "pkgs.jdk16"
     };

     v2ray = {
       enable = true;
       configFile = "/opt/env/v2ray/config.json";

     };

     zerotierone = {
       enable = true;
       joinNetworks = ["af78bf94369e9f0b" ];
     };

   };


  fileSystems = {
    "/data" = {
      device = "/dev/disk/by-label/DATA";
      fsType = "ntfs";
    };
#     "/opt" = {
#      device = "/dev/disk/by-label/opt";
#      fsType = "ext4";
#    };
  };

  virtualisation = {
     #docker = {
     #  enable = false;
     #};
  }; 

  # Define a user account. Don't forget to set a password with ‘passwd’.
   users.users.dnf = {
     isNormalUser = true;
     extraGroups = [ "wheel" "docker" "tomcata" "netdata"]; # Enable ‘sudo’ for the user.
   };

  # This value determines the NixOS release with which your system is to be
  # compatible, in order to avoid breaking some software such as database
  # servers. You should change this only after NixOS release notes say you
  # should.
  system.stateVersion = "20.09"; # Did you read the comment?

}

